<%@ page contentType="text/html;charset=UTF-8"%>

<link rel="stylesheet" href="${az}/assets/css/bootstrap.min.css">
<%--<link rel="stylesheet" href="${az}/assets/css/font-awesome.min.css">--%>
<%--<link rel="stylesheet" href="${az}/assets/css/nprogress.css">--%>
<%--<link rel="stylesheet" href="${az}/assets/css/animate.min.css">--%>
<%--<link rel="stylesheet" href="${az}/assets/css/custom.min.css">--%>

<link rel="stylesheet" type="text/css" href="${az}/assets/themes/metro/easyui.css">
<%--<link rel="stylesheet" type="text/css" href="${az}/assets/themes/icon.css">--%>

<script src="${az}/assets/js/jquery-1.8.0.min.js"></script>
<script src="${az}/assets/js/jquery.easyui.min.js"></script>
<script src="${az}/assets/js/jquery.form.js"></script>


<script src="${az}/assets/locale/easyui-lang-zh_CN.js"></script>

<%--<link href="http://cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">--%>
<link rel="stylesheet" href="${az}/assets/css/font-awesome.min.css">


<style>

    /** frame *******************************/

    .azeroth-red {
        color:#ea644a;
    }
    .azeroth-green {
        color:#38b03f;
    }

    html, body {
        height:100%; padding:0; margin:0;
    }

    .window-mask {
        background-color: rgb(0, 0, 0);
        opacity: 0.3;
    }
    .window {
        padding: 0px;
        border-width: 0px;
        border-radius: 7px;
        box-shadow: 1px 1px 50px rgba(0,0,0,.3);
    }
    .window, .panel, .window-shadow {
        border-radius: 7px;
    }
    .azeroth-tabs panel panel-body {
        border-radius: 0px;
    }
    .window-shadow {
        background: #000;
        -moz-box-shadow: 1px 1px 50px rgba(0,0,0,.3);
        -webkit-box-shadow: 1px 1px 50px rgba(0,0,0,.3);
        box-shadow: 1px 1px 50px rgba(0,0,0,.3);
        filter: progid:DXImageTransform.Microsoft.Blur(pixelRadius=2,MakeShadow=false,ShadowOpacity=0.2);
    }
    .window .window-body {
        border-width: 1px;
        border-style: solid;
        border-top-width: 1px;
        overflow-y: hidden;
    }
    .window .window-header {
        border: 0px solid rgba(0,0,0,.3);
        border-bottom-width: 0px;
    }
    .window .window-header {
        background: transparent;
        padding: 0;
    }
    .dialog-button {
        border-top-width: 0px;
        top: 0px;
    }

    .panel-tool a {
        margin: 0px 8px 0 0px;
    }

    .panel-body {
        font-size: 14px;
    }

    .panel-title {
        font-size: 15px;
        height: 42px;
        line-height: 42px;
        background: #393d49;
        padding: 0 0 0 5px;
        color: #fff;
    }
    .dialog-button {
        background: #dcdcdc;
    }

    .datagrid-htable, .datagrid-btable, .datagrid-ftable {
        color: #444;
        border-collapse: separate;

    }
    .datagrid-header {
        background-color: #f1f1f1;
    }

    .form-horizontal .form-group {
        margin-right: 0px;
        margin-left: 0px;
    }
    .label-txt {
        float: right;
    }
    .star {
        color: red;
        padding-right: 5px;
        font-size: 16px;
        float: right;
    }
    .form-group p {
        font-size: 13px;
        font-weight: normal;
    }
    .form-control {
        font-size: 14px;
        border-radius: 0px;
    }
    .form_100 {
        width:100%; height:34px; line-height:34px;
    }

    .fa {
        font-size: 14px;
    }

    /*表单内容*/
    .validatebox-text, textarea, .combo, .panel-body-noheader, .combobox-item, .combo-p {
        border-radius: 2px;
        -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
        box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
        -webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
        -o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
        transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
    }
    .combo-p {
        border: 1px solid #ddd;
    }
    .combobox-item {
        height:32px;
        line-height:26px;
    }
    .combo-p {
        margin-top: 3px;
    }

    .textbox-addon-right a:after {
        content: "";
        width:0;
        height:0;

        right: -3px;
        top: 15px;

        border-width:6px 6px 0;
        border-style:solid;
        border-color:#333 transparent transparent;/*灰 透明 透明 */
        margin:10px auto;
        position:relative;
    }
    .combo-arrow:hover {
        background-color: #fff;
    }
    .combo-arrow {
         background: #fff;
    }

    /*表格美化*/
    .datagrid-htable td, .datagrid-btable td {
        min-height: 20px;
        line-height: 20px;
        padding: 9px 15px;
    }
    /*.datagrid-row:nth-of-type(even) {
        background: #ffd1c5;
    }*/
    .datagrid-row-selected {
        background: #FFE7DF;
    }

    .datagrid-cell, .datagrid-cell-group, .datagrid-header-rownumber, .datagrid-cell-rownumber {
        height: 20px;
        line-height: 20px;
        font-size: 14px;
    }
    .datagrid-header .datagrid-cell span {
        font-size: 14px;
    }

    /* 表格查询功能美化 */
    .l-btn-text {
        display: inline-block;
        vertical-align: top;
        width: auto;
        line-height: 24px;
        font-size: 14px;
        padding: 0;
        margin: 0 4px;
    }

</style>

<script>

    // 全局变量
    var $AzerothData = {};

    // 保存所有方法
    $AzerothData.methods = {};
    // 弹出框
    $AzerothData.dialog = null;

    // 高度自适应
    $AzerothData.autoHeight = function() {
        $("#azeroth_layout_center").css("height", ($(window).height()-70)+"px");
        $("#tabs").css("height", ($(window).height()-70)+"px");
    }

    $AzerothData.statusCode = function(_data) {
        _data = eval("("+_data+")");
        if(_data.state==0) {
            return true;
        }

        if(_data.code="E0103") {
            alert("当前管理员不存在");
        } else {
            alert(_data.msg);
        }
        return false;
    }

    // 添加标签页，没有新增，有刷新
    $AzerothData.methods.addTabs = function(_name, _url, _id) {
        if(_url=="#") {
            return false;
        }
        var tabs = $("#tabs");
        var content = '<iframe scrolling="auto" frameborder="0"  src="'+_url+'" style="width:100%; height:98.5%; overflow-y:hidden;"></iframe>';

        if(tabs.tabs("exists", _name)) {
            tabs.tabs('select', _name);
            var current_tab = $('#tabs').tabs('getSelected');

            tabs.tabs('update', {
                tab: current_tab,
                options: {
                    //href: _url  // 新内容的URL
                    content: content
                }
            });

        } else {
            tabs.tabs('add',{
                title: _name,
                content: content,
                closable:true,
                //href: _url
            });
            var index = tabs.tabs('getTabIndex', tabs.tabs('getSelected'));
            tabs.tabs("select", 0);
            tabs.tabs("select", index);
        }

        $('#tabs').tabs('resize');

    }

    // 表单序列化
    $AzerothData.methods.serializeObject = function(form) {
        var o={};
        $.each(form.serializeArray(),function(index){
            if(o[this['name']]){
                o[this['name']] = o[this['name']] + "," + this['value'];
            }else{
                o[this['name']] = this['value'];
            }
        })
        return o;
    }

    // 弹出窗，添加
    $AzerothData.methods.dialogAdd = function(data) {
        // 生成按钮
        $AzerothData.methods.buttons(data);

        // 生成弹出窗
        $AzerothData.dialog = parent.$.dialog(data);
    }

    // 弹出窗，编辑
    $AzerothData.methods.dialogEdit = function(data) {
        var row = data.datagrid.datagrid('getSelected');
        if(row==null){
            parent.$.messager.alert("提示", $AzerothData.methods.errorMsg("请选择一行数据！"), "error");
            return false;
        }

        // 拼接主键
        if(data.uidName!=null) {
            data.href = data.href + '&' + data.uidName + '=' + row[data.uidName];
        } else {
            data.href = data.href + '&uid=' + row.uid;
        }

        // 生成按钮
        $AzerothData.methods.buttons(data);
        // 生成弹出窗
        $AzerothData.dialog = parent.$.dialog(data);
    }

    // 删除
    $AzerothData.methods.dialogDelete = function(data) {
        var row = data.datagrid.datagrid('getSelected');
        if(row==null){
            parent.$.messager.alert("提示", $AzerothData.methods.errorMsg("请选择一行数据！"), "error");
            return false;
        }

        if(data.delName!=null) {
            data.msg = data.msg+'【'+row[data.delName]+'】';
        } else {
            data.msg = data.msg+'【'+row.funName+'】';
        }

        parent.$.messager.confirm('提示', data.msg, function(flag) {
            //console.info(data);
            if(flag) {
                parent.$.post(data.href, {uid : row.uid}, function(json) {
                    // TODO - 权限控制
                    //if($AzerothData.methods.statusMsg(json)) {
                        parent.$.messager.alert("提示","删除成功！","info", function() {
                            data.datagrid.datagrid('reload');
                        });
                    //}
                }, "JSON");
            }
        });
    }

    // 通用请求操作
    $AzerothData.methods.dialogAjax = function(data) {
        var row = data.datagrid.datagrid('getSelected');
        if(row==null){
            parent.$.messager.alert("提示", $AzerothData.methods.errorMsg("请选择一行数据！"), "error");
            return false;
        }

        if(data.opeName!=null) {
            data.msg = data.msg+'【'+row[data.opeName]+'】';
        } else {
            data.msg = data.msg+'【'+row.funName+'】';
        }

        parent.$.messager.confirm('提示', data.msg, function(flag) {
            if(flag) {
                parent.$.post(data.href, data.field, function(json) {
                    if($AzerothData.methods.statusMsg(json)) {
                        parent.$.messager.alert("提示",data.prompt,"info", function() {
                            data.datagrid.datagrid('reload');
                        });
                    }
                }, "JSON");
            }
        });
    }

    // 解析ajax返回值
    $AzerothData.methods.statusMsg = function(json) {
        var state = json.state;
        var msg = json.msg;

        if(state!=0) {
            parent.$.messager.alert("提示", msg, "error", function() {

            });
            return false;
        }

        return true;
        /*var code = json.errcode;
        var msg = json.errmsg;
        var content = "错误代码：" + code + "<br/>";
        content+= msg;
        content = "<font style='color:red;'>"+content+"</font>";
        if(code == "0"){//成功
            return true;
        }else if(code=="997"){//登录超时
            sessionDialog(content);
            return false;
        }else if(code=="998"){//没有相关权限
            try {
                powerDialog(content);
            } catch (e) {
                powerDialog(content);
            }
            return false;
        }else{
            parent.parent.$.messager.alert("提示",content,"error");
            return false;
        }
        return false;*/
    };

    // 返回按钮组
    $AzerothData.methods.buttons = function(data) {
        for(var i=0; i<data.buttons.length; i++) {
            var button = data.buttons[i];
            if(button.type=='save') {
                button.handler = function(){
                    $AzerothData.dialog.find('iframe').get(0).contentWindow.$objData.submitForm($AzerothData.dialog, data.datagrid);
                }
            }
            if(button.type=='back') {
                button.handler = function(){
                    $AzerothData.dialog.dialog('destroy');
                }
            }
        }
    }

    // 错误信息提示文字
    $AzerothData.methods.errorMsg = function(msg) {
        return "<span style='color:red;'>"+msg+"</span>";
    }

    // 格式化时间
    Date.prototype.format = function (fmt) { //author: meizz
        var o = {
            "M+": this.getMonth() + 1, //月份
            "d+": this.getDate(), //日
            "h+": this.getHours(), //小时
            "m+": this.getMinutes(), //分
            "s+": this.getSeconds(), //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }

    // 弹出窗
    $.dialog = function(options) {
        var _default = {
            minimizable: false,
            modal: true,
            collapsible: false,
            maximizable: false,
            href:null,
            content:null,
            onClose: function() {
                $(this).dialog('destroy');
            }
        };
        options = $.extend(_default, options);
        var dialog = $(options.el || "<div/>");
        if (options.bodyStyle) {
            dialog.css(options.bodyStyle);
        }

        if (options.href) {
            options.content = '<iframe id="iframe1" src="' + options.href + '" allowTransparency="true" scrolling="auto" width="100%" height="99%" frameBorder="0" name="iframe1"></iframe>';
        }
        options.href=null;
        dialog.dialog(options);

        $("#iframe1").on("load",function(){
            parent.$.messager.progress('close');
            parent.parent.$.messager.progress('close');
        });
        dialog.close = function() {
            dialog.dialog('destroy');
        };
        return dialog;
    };
</script>
